package com.zy.web.demo.duoxiancheng.demo32;

import java.util.Random;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author <a href="mailto:zhouyong@cqyyt.com">zy</a>
 * @version 1.0
 * @date 2020/9/7 15:56
 */
public class Service32A {

    private ReentrantLock lock = new ReentrantLock();
    private Condition condition = lock.newCondition();

    public void method(){
        try {
            lock.lockInterruptibly();
            System.out.println("begin name="+Thread.currentThread().getName());
            for (int i = 0; i <Integer.MAX_VALUE/10 ; i++) {
                Math.random();
            }
            System.out.println("end name="+Thread.currentThread().getName());

        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            if ( lock.isHeldByCurrentThread() ){
                lock.unlock();
            }
        }
    }

}
